<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #dept_id="{ record }">
        <a-tag color="blue">{{ record.dept.name }}</a-tag>
      </template>
      <template #summaryCell="{ column, record, rowIndex }">
        {{
          column.dataIndex == "dept_id"
            ? "合计"
            : column.dataIndex == "before_weight" || column.dataIndex == "after_weight"
            ? (record[column.dataIndex] - 0).toFixed(3)
            : record[column.dataIndex]
        }}
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive,onActivated } from 'vue'
import warehouseInventory from '@/api/warehouse/warehouseInventory'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const is_shuaxin = ref(false)
onActivated(() => {
		if(is_shuaxin.value){
			crudRef.value.refresh()
		}
		
	})
const numberOperation = (newValue, id, numberName) => {
  warehouseInventory.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  warehouseInventory.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_warehouse_inventory',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: false,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  showSummary: true,
  summary: [
    {
      dataIndex: "before_number",
      action: "sum",
    },
    {
      dataIndex: "before_weight",
      action: "sum",
    },
    {
      dataIndex: "after_number",
      action: "sum",
    },
    {
      dataIndex: "after_weight",
      action: "sum",
    },
  ],
  api: warehouseInventory.getList,
  recycleApi: warehouseInventory.getRecycleList,
  add: {
    show: false,
    api: warehouseInventory.save,
    auth: ['warehouse:inventory:save']
  },
  edit: {
    show: false,
    api: warehouseInventory.update,
    auth: ['warehouse:inventory:update']
  },
  delete: {
    show: false,
    api: warehouseInventory.deletes,
    auth: ['warehouse:inventory:delete'],
    realApi: warehouseInventory.realDeletes,
    realAuth: ['warehouse:inventory:realDeletes']
  },
  recovery: {
    show: false,
    api: warehouseInventory.recoverys,
    auth: ['warehouse:inventory:recovery']
  },
  import: {
    show: false,
    url: 'warehouse/inventory/import',
    templateUrl: 'warehouse/inventory/downloadTemplate',
    auth: ['warehouse:inventory:import']
  },
  export: {
    show: false,
    url: 'warehouse/inventory/export',
    auth: ['warehouse:inventory:export']
  },
  afterRequest:(params)=>{
    params.map((v,i)=>{
      v.before_weight = (v.before_weight - 0)
      v.after_weight = (v.after_weight - 0)
    })
    is_shuaxin.value = true
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "公司名称",
    dataIndex: "dept_id",
    align: "center",
    formType: "select",
    width: 200,
    fixed: "left",
    search: true,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: "system/dept/remote",
      // 指定组件接收的props
      props: { label: "name", value: "id" },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "name"],
        // 设置数据过滤
        filter: {
          type: ["=", 2],
          status: ['=',1]
        },
        // 关联模型
        relations: [],
      },
    },
  },
  {
    title: "车号",
    dataIndex: "wareuserdetail.car_no",
    formType: "input",
    align: "center",
    search: true,
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "合同号",
    dataIndex: "wareuserdetail.contract_no",
    formType: "input",
    align: "center",
    search: true,
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "品名",
    dataIndex: "wareuserdetail.goods_name",
    formType: "input",
    align: "center",
    search: true,
    addDisplay: false,
    editDisplay: false,
  },
 
  
  
  {
    title: "箱号",
    dataIndex: "wareuserdetail.box",
    formType: "input",
    search: true,
    align: "center",
    width:100,
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "集装箱名称",
    dataIndex: "wareuserdetail.box_type",
    formType: "input",
    align: "center",
    addDisplay: false,
    editDisplay: false,
  },
  
  {
    title: "盘点前件数(件)",
    dataIndex: "before_number",
    formType: "input",
    align: "center",
    search: false
  },
  {
    title: "盘点前重量(吨)",
    dataIndex: "before_weight",
    formType: "input",
    align: "center",
    search: false
  },
  {
    title: "盘点前仓位",
    dataIndex: "before_warehouse",
    formType: "input",
    align: "center",
    search: false
  },
  {
    title: "盘点后数量(件)",
    dataIndex: "after_number",
    formType: "input",
    align: "center",
    search: false
  },
  {
    title: "盘点后重量(吨)",
    dataIndex: "after_weight",
    formType: "input",
    align: "center",
    search: false
  },
  {
    title: "盘点后仓位",
    dataIndex: "after_warehouse",
    formType: "input",
    align: "center",
    search: false
  },
  {
    title: "盘点说明",
    dataIndex: "remark",
    align: "center",
    formType: "editor",
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "操作者",
    dataIndex: "create_user.nickname",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false,
  },
  {
    title: "时间",
    dataIndex: "created_at",
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input", 
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'warehouse:inventory' } </script>